/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InterfazAdministrarProfesor.java
 *
 * Created on 27/10/2011, 07:43:31 PM
 */
package presentacion;

import Paneles.PanelGeneral;
import business.ProfesorBo;
import dominio.Profesor;
import java.awt.BorderLayout;
import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.StringTokenizer;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
 *
 * @author vanessa
 */
public class InterfazAdministrarProfesor extends javax.swing.JFrame {

    private boolean consulta;
    private String[] docProf;
    private ImageIcon icono;

    /**
     * Creates new form InterfazAdministrarProfesor
     */
    public InterfazAdministrarProfesor() {
        initComponents();
        PanelGeneral panel = new PanelGeneral();
        this.add(panel, BorderLayout.SOUTH);
        icono = new ImageIcon(getClass().getResource("/Imagenes/icon.gif"));
        this.setIconImage(icono.getImage());
        Calendar fechaAct = Calendar.getInstance();
        int añadir = fechaAct.get(Calendar.YEAR) - 2009;
        if (añadir > 0) {
            for (int i = 0; i < añadir; i++) {
                cboAnnio.addItem(String.valueOf(2009 + i + 1));

            }
        }
        cboListaProfs.setEnabled(false);
        btnCrearPror.setEnabled(false);
        btnActualizarProf.setEnabled(false);


    }

    public void calcularEdad() {
        Calendar fechaAct = Calendar.getInstance(),
                fechaNac = Calendar.getInstance();
        int edad;

        if (cboDia.getSelectedIndex() == 0 || cboMes.getSelectedIndex() == 0 || cboAnnio.getSelectedIndex() == 0) {
            tfEdadProf.setText("--");
        } else {
            int dia = Integer.parseInt((String) cboDia.getSelectedItem()),
                    mes = cboMes.getSelectedIndex(),
                    año = Integer.parseInt((String) cboAnnio.getSelectedItem());

            fechaNac.set(fechaAct.get(Calendar.YEAR), mes - 1, dia);//año actual con dia y mes de nacimiento el mes es en base 0(mayo es 4)
            if (fechaAct.getTime().before(fechaNac.getTime())) {//descubriendo si el dia de hoy es despues del dia cumpleaños
                edad = fechaAct.get(Calendar.YEAR) - año - 1;
            } else {
                edad = fechaAct.get(Calendar.YEAR) - año;
            }
            tfEdadProf.setText(String.valueOf(edad));
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        tfEspecialidadProf = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        tfNombreUsuario = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tfTelProf = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        tfEdadProf = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        tfCelProf = new javax.swing.JTextField();
        tfAddressProf = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        tfDocProf = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        tfNombreProf = new javax.swing.JTextField();
        tfApellidoProf = new javax.swing.JTextField();
        btnCrearPror = new javax.swing.JButton();
        cboDia = new javax.swing.JComboBox();
        cboMes = new javax.swing.JComboBox();
        cboAnnio = new javax.swing.JComboBox();
        cboGenero = new javax.swing.JComboBox();
        jSeparator1 = new javax.swing.JSeparator();
        lblNombreUsiuario = new javax.swing.JLabel();
        btnActualizarProf = new javax.swing.JButton();
        cboListaProfs = new javax.swing.JComboBox();
        rBtnCrearProf = new javax.swing.JRadioButton();
        rBtnActualizarProf = new javax.swing.JRadioButton();
        btnCancelar = new javax.swing.JButton();
        lblPasswd = new javax.swing.JLabel();
        ptfPasswd = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Crear Profesor");
        setResizable(false);

        jLabel4.setText("Especialidad:");

        jLabel5.setForeground(new java.awt.Color(253, 251, 251));
        jLabel5.setText("Género (*) :");

        tfNombreUsuario.setEditable(true);

        jLabel6.setText("Teléfono Fijo:");

        jLabel8.setText("Dirección:");

        jLabel3.setText("Edad:");

        tfEdadProf.setEditable(false);
        tfEdadProf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfEdadProfActionPerformed(evt);
            }
        });

        jLabel2.setText("Documento de Identificación (*) :");

        jLabel9.setForeground(new java.awt.Color(240, 224, 224));
        jLabel9.setText("Fecha de Nacimiento (*) :");

        jLabel7.setText("Teléfono Móvil (*) :");

        tfDocProf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfDocProfActionPerformed(evt);
            }
        });

        jLabel1.setText("Nombre del Profesor (*) :");

        jLabel11.setText("Apellidos del Profesor (*) :");

        btnCrearPror.setText("Crear Profesor");
        btnCrearPror.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCrearProrActionPerformed(evt);
            }
        });

        cboDia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Dia", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        cboDia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboDiaActionPerformed(evt);
            }
        });

        cboMes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mes", "ENERO", "FEBRERO", "MARZO", "ABRIL", "MAYO", "JUNIO", "JULIO", "AGOSTO", "SEPTIEMBRE", "OCTUBRE", "NOVIEMBRE ", "DICIEMBRE" }));
        cboMes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboMesActionPerformed(evt);
            }
        });

        cboAnnio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Año", "1900", "1901", "1902", "1903", "1904", "1905", "1906", "1907", "1908", "1909", "1910", "1911", "1912", "1913", "1914", "1915", "1916", "1917", "1918", "1919", "1920", "1921", "1922", "1923", "1924", "1925", "1926", "1927", "1928", "1929", "1930", "1931", "1932", "1933", "1934", "1935", "1936", "1937", "1938", "1939", "1940", "1941", "1942", "1943", "1944", "1945", "1946", "1947", "1948", "1949", "1950", "1951", "1952", "1953", "1954", "1955", "1956", "1957", "1958", "1959", "1960", "1961", "1962", "1963", "1964", "1965", "1966", "1967", "1968", "1969", "1970", "1971", "1972", "1973", "1974", "1975", "1976", "1977", "1978", "1979", "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009" }));
        cboAnnio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboAnnioActionPerformed(evt);
            }
        });

        cboGenero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione:", "FEMENINO\t", "MASCULINO" }));

        lblNombreUsiuario.setForeground(new java.awt.Color(251, 237, 237));
        lblNombreUsiuario.setText("Nombre de Usuario (*) : ");

        btnActualizarProf.setText("Actualizar Profesor");
        btnActualizarProf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActualizarProfActionPerformed(evt);
            }
        });

        cboListaProfs.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione" }));
        cboListaProfs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboListaProfsActionPerformed(evt);
            }
        });

        rBtnCrearProf.setBackground(new java.awt.Color(118, 104, 230));
        rBtnCrearProf.setText("CREAR PROFESOR");
        rBtnCrearProf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rBtnCrearProfActionPerformed(evt);
            }
        });

        rBtnActualizarProf.setBackground(new java.awt.Color(118, 104, 230));
        rBtnActualizarProf.setText("ACTUALIZAR O CONSULTAR PROFESOR");
        rBtnActualizarProf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rBtnActualizarProfActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        lblPasswd.setForeground(new java.awt.Color(244, 232, 232));
        lblPasswd.setText("Contraseña (*) : ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnCrearPror)
                        .addGap(30, 30, 30)
                        .addComponent(btnActualizarProf)
                        .addGap(28, 28, 28)
                        .addComponent(btnCancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(cboListaProfs, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(rBtnCrearProf)
                                    .addGap(18, 18, 18)
                                    .addComponent(rBtnActualizarProf)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel11)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel5)
                                    .addComponent(lblNombreUsiuario)
                                    .addComponent(lblPasswd))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(tfNombreProf)
                                    .addComponent(tfApellidoProf)
                                    .addComponent(tfDocProf)
                                    .addComponent(tfEspecialidadProf)
                                    .addComponent(tfTelProf)
                                    .addComponent(tfCelProf)
                                    .addComponent(tfAddressProf)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(cboGenero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jLabel3))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(cboDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(cboMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(tfEdadProf, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(cboAnnio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(tfNombreUsuario, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(ptfPasswd))))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cboAnnio, tfEdadProf});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnActualizarProf, btnCrearPror});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rBtnCrearProf)
                    .addComponent(rBtnActualizarProf))
                .addGap(9, 9, 9)
                .addComponent(cboListaProfs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfNombreProf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(tfApellidoProf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tfDocProf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tfEspecialidadProf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(tfTelProf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(tfCelProf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(tfAddressProf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(cboDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboAnnio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(cboGenero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(tfEdadProf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblNombreUsiuario)
                    .addComponent(tfNombreUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(lblPasswd, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(ptfPasswd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnActualizarProf)
                    .addComponent(btnCrearPror)
                    .addComponent(btnCancelar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCrearProrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCrearProrActionPerformed
        String fechaNac = (String) cboDia.getSelectedItem() + "-" + String.valueOf(cboMes.getSelectedIndex()) + "-" + (String) cboAnnio.getSelectedItem();
        String usuario = tfNombreUsuario.getText();
        char[] passArray = ptfPasswd.getPassword();
        String passwd = new String(passArray);
        if (tfNombreProf.getText().equals("") || tfApellidoProf.getText().equals("")
                || tfCelProf.getText().equals("") || tfDocProf.getText().equals("")
                || ptfPasswd.getText().equals("") || cboGenero.getSelectedItem().equals("")
                || cboAnnio.getSelectedItem().equals("Año") || cboMes.getSelectedItem().equals("Mes")
                || cboDia.getSelectedItem().equals("Dia") || cboGenero.getSelectedItem().equals("Seleccione:")) {
            JOptionPane.showMessageDialog(this, "Por favor llene los campos marcados con (*)");
        } else {

            try {
                long docProfesor;
                docProfesor = Long.parseLong(tfDocProf.getText());
                ProfesorBo bo = new ProfesorBo();

                Profesor profesor = bo.crearProfesor(tfNombreProf.getText(),
                        tfApellidoProf.getText(), docProfesor,
                        tfEspecialidadProf.getText(), tfTelProf.getText(),
                        tfCelProf.getText(), tfAddressProf.getText(),
                        fechaNac, (String) cboGenero.getSelectedItem(), Integer.parseInt(tfEdadProf.getText()), usuario, passwd);
                consulta = false;
                if (profesor == null) {
                    JOptionPane.showMessageDialog(this, "No se pudo crear el profesor, Asegurese de ingresar los datos correctos.");
                } else {
                    JOptionPane.showMessageDialog(this, "profesor creado correctamente.");
                    tfAddressProf.setText("");
                    tfApellidoProf.setText("");
                    tfCelProf.setText("");
                    tfDocProf.setText("");
                    tfEdadProf.setText("");
                    tfEspecialidadProf.setText("");
                    tfNombreProf.setText("");
                    tfNombreUsuario.setText("");
                    tfTelProf.setText("");
                    ptfPasswd.setText("");
                }

            } catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(this, "El formato de la cedula no es el adecuado");

            }

        }

    }//GEN-LAST:event_btnCrearProrActionPerformed

    private void cboDiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboDiaActionPerformed
        calcularEdad();
    }//GEN-LAST:event_cboDiaActionPerformed

    private void cboMesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboMesActionPerformed
        calcularEdad();
    }//GEN-LAST:event_cboMesActionPerformed

    private void cboAnnioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboAnnioActionPerformed
        calcularEdad();
    }//GEN-LAST:event_cboAnnioActionPerformed

    private void rBtnActualizarProfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rBtnActualizarProfActionPerformed
        rBtnActualizarProf.setSelected(true);
        btnActualizarProf.setEnabled(true);
        btnCrearPror.setEnabled(false);
        rBtnCrearProf.setSelected(false);
        cboListaProfs.setEnabled(true);
        ptfPasswd.setVisible(false);
        lblNombreUsiuario.setVisible(false);
        lblPasswd.setVisible(false);
        tfDocProf.setEditable(false);
        tfNombreUsuario.setVisible(false);
        consultarProfesores();

    }//GEN-LAST:event_rBtnActualizarProfActionPerformed

    private void rBtnCrearProfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rBtnCrearProfActionPerformed
        rBtnCrearProf.setSelected(true);
        btnCrearPror.setEnabled(true);
        btnActualizarProf.setEnabled(false);
        rBtnActualizarProf.setSelected(false);
        cboListaProfs.setEnabled(false);
    }//GEN-LAST:event_rBtnCrearProfActionPerformed

    private void cboListaProfsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboListaProfsActionPerformed
        ProfesorBo bo = new ProfesorBo();
        Profesor p = bo.encontrarProfesor(Long.valueOf(docProf[cboListaProfs.getSelectedIndex()]));
        tfNombreProf.setText(p.getNombreProfesor());
        tfApellidoProf.setText(p.getApellidoProfesor());
        tfDocProf.setText(String.valueOf(p.getDocProfesor()));
        tfDocProf.setEditable(false);
        tfEspecialidadProf.setText(p.getEspecialidad());
        tfTelProf.setText(p.getTelFijo());
        tfCelProf.setText(p.getTelMovil());
        tfAddressProf.setText(p.getDireccionProf());
        StringTokenizer token = new StringTokenizer(p.getFechaNacimientoProf(), "-");
        cboDia.setSelectedIndex(Integer.valueOf(token.nextToken()));
        cboMes.setSelectedIndex(Integer.valueOf(token.nextToken()));
        cboAnnio.setSelectedIndex(Integer.valueOf(token.nextToken()) - 1899);
        cboGenero.setSelectedItem(p.getGeneroProf());
        tfEdadProf.setText(String.valueOf(p.getEdadProf()));
        tfNombreUsuario.setEditable(true);
        tfNombreUsuario.setText(p.getNombreUsuario());
        tfNombreUsuario.setEditable(false);

    }//GEN-LAST:event_cboListaProfsActionPerformed

    private void btnActualizarProfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualizarProfActionPerformed
        String fechaNac = (String) cboDia.getSelectedItem() + "-" + String.valueOf(cboMes.getSelectedIndex()) + "-" + (String) cboAnnio.getSelectedItem();
        ProfesorBo bo = new ProfesorBo();

        boolean profesor = bo.actualizarProfesor(Long.valueOf(docProf[cboListaProfs.getSelectedIndex()]), tfNombreProf.getText(),
                tfApellidoProf.getText(),
                tfEspecialidadProf.getText(), tfTelProf.getText(),
                tfCelProf.getText(), tfAddressProf.getText(),
                fechaNac, (String) cboGenero.getSelectedItem(),
                Integer.parseInt(tfEdadProf.getText()));

        if (profesor) {
            JOptionPane.showMessageDialog(this, "Profesor actualizado correctamente");
        } else {
            JOptionPane.showMessageDialog(this, "Error al actualizar al profesor.");
        }
    }//GEN-LAST:event_btnActualizarProfActionPerformed

    private void tfDocProfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfDocProfActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfDocProfActionPerformed

    private void tfEdadProfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfEdadProfActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfEdadProfActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_btnCancelarActionPerformed
    private void consultarProfesores() {
        if (consulta == false) {
            cboListaProfs.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Seleccione"}));
            String nombreProf = "", toStringProf;
            ProfesorBo bo = new ProfesorBo();
            Collection<Profesor> p = bo.encontrarProfesores();
            docProf = new String[p.size() + 1];
            docProf[0] = "default0";
            Iterator<Profesor> it = p.iterator();
            int i = 1, numToken;
            while (it.hasNext()) {
                numToken = 1;
                nombreProf = "";
                toStringProf = it.next().toString();
                StringTokenizer token = new StringTokenizer(toStringProf);
                while (token.hasMoreTokens()) {//mientras el tostrin de profesor tiene mas palabras
                    if (numToken == 1) {// si es el token 1, yo se que es el documento
                        docProf[i] = "" + token.nextToken();
                    } // si no, yo se que viene el nombre y el apellido
                    else {
                        nombreProf += token.nextToken() + " ";
                    }
                    numToken++;
                }
                cboListaProfs.addItem(nombreProf + " Doc: " + docProf[i]);
                i++;
            }
            consulta = true;
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InterfazAdministrarProfesor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnActualizarProf;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnCrearPror;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.JComboBox cboAnnio;
    private javax.swing.JComboBox cboDia;
    private javax.swing.JComboBox cboGenero;
    private javax.swing.JComboBox cboListaProfs;
    private javax.swing.JComboBox cboMes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblNombreUsiuario;
    private javax.swing.JLabel lblPasswd;
    private javax.swing.JPasswordField ptfPasswd;
    private javax.swing.JRadioButton rBtnActualizarProf;
    private javax.swing.JRadioButton rBtnCrearProf;
    private javax.swing.JTextField tfAddressProf;
    private javax.swing.JTextField tfApellidoProf;
    private javax.swing.JTextField tfCelProf;
    private javax.swing.JTextField tfDocProf;
    private javax.swing.JTextField tfEdadProf;
    private javax.swing.JTextField tfEspecialidadProf;
    private javax.swing.JTextField tfNombreProf;
    private javax.swing.JTextField tfNombreUsuario;
    private javax.swing.JTextField tfTelProf;
    // End of variables declaration//GEN-END:variables
}
